import { column } from 'element-plus/es/components/table-v2/src/common'
import { reactive, ref } from 'vue'
import { VxeGridProps } from 'vxe-table'
import { useDictStore } from '@/store/modules/dict'

const dictStore = useDictStore()
interface Rows {
  idNo: string
  secretsName: string
  secretsType: string
  date: string
  inventor: string
  unit: string
  submitDate: string
}

const selectOptions = reactive([
  {
    label: '博士',
    value: '0',
  },
  {
    label: '硕士',
    value: '1',
  },
  {
    label: '学士',
    value: '2',
  },
])

const gridOptions = reactive<VxeGridProps<any>>({
  border: true,
  height: 300,
  align: 'center',
  loading: false,
  showOverflow: true,
  autoResize: true,
  columnConfig: {
    resizable: true,
    minWidth: '100px',
  },
  columns: [
    // { title: '序号', type: 'seq', width: 50 },
    { field: 'id', title: '申报记录ID', width: 100 },
    { field: 'achievementId', title: '成果登记号' },
    { field: 'recommendUnit', title: '推荐单位' },
    { field: 'recommendDate', title: '推荐日期' },
    { field: 'recommendLevel', title: '推荐等级' },
    { field: 'preReviewLevel', title: '初评等级' },
    { field: 'topicType', title: '课题类型' },
    { field: 'subjectArea', title: '专业领域' },
    {
      field: 'researchStartDate',
      title: '研究开始时间',
      width: 120,
      formatter: ['formatDate', 'yyyy-MM-dd'],
    },
    {
      field: 'researchEndDate',
      title: '研究结束时间',
      width: 120,
      formatter: ['formatDate', 'yyyy-MM-dd'],
    },
    { field: 'estimatedBudget', title: '预计投入经费(万元)', width: 150 },
    {
      field: 'externalCooperationRequired',
      title: '是否需要外协',
      width: 120,
      formatter({ cellValue }) {
        return cellValue == '1' ? '是' : '否'
      },
    },
    { field: 'leadingUnitName', title: '承担单位' },
    { field: 'collaboratingUnitNames', title: '协作单位' },
    { field: 'projectCode', title: '项目编号' },
    { field: 'projectName', title: '项目名称' },
    { field: 'projectLevel', title: '项目等级' },
    { field: 'projectType', title: '项目类型' },
    { field: 'keyProject', title: '是否重点项目', width: 120 },
    { field: 'projectHeaderName', title: '项目负责人' },
    { field: 'reportUnitName', title: '上报单位' },
    { field: 'reportPersonName', title: '上报人' },
    {
      field: 'createTime',
      title: '记录创建时间',
      formatter: ['formatDate', 'yyyy-MM-dd'],
      width: 120,
    },
    {
      title: '操作',
      width: 200,
      slots: { default: 'operate' },
      fixed: 'right',
    },
  ],
  data: [],
})

const valueoptions = reactive([
  {
    label: '课题名称',
    value: 'secretsName',
  },
  {
    label: '课题编号',
    value: 'unit',
  },
  {
    label: '课题负责人',
    value: 'date',
  },
  {
    label: '项目名称',
    value: 'date',
  },
  {
    label: '项目编号',
    value: 'date',
  },
  {
    label: '项目负责人',
    value: 'date',
  },
  {
    label: '预算申请ID',
    value: 'date',
  },
  {
    label: '上报人',
    value: 'date',
  },
])

interface from {
  label: string
  prop: string
  type: string //select / date /tree
  options?: Array<{ label: string; value: string }>
}

const formList = ref<Array<from>>([
  {
    label: '推荐等级：',
    prop: 'recommendLevel',
    type: 'select',
    options: dictStore.getDictType('recommend_level'),
  },
  {
    label: '推荐单位：',
    prop: 'recommendUnit',
    type: 'select',
    options: [],
  },
  {
    label: '推荐日期：',
    prop: 'recommendDate',
    type: 'date',
  },
  {
    label: '课题类型：',
    prop: 'topicType',
    type: 'select',
    options: dictStore.getDictType('topic_type'),
  },
  {
    label: '专业领域：',
    prop: 'subjectArea',
    type: 'tree',
    options: dictStore.getDictType('professional_field'),
  },
  {
    label: '是否需要外协：',
    prop: 'externalCooperationRequired',
    type: 'select',
    options: [
      { label: '是', value: '1' },
      { label: '否', value: '2' },
    ],
  },
  {
    label: '研究开始时间：',
    prop: 'researchStartBefore',
    type: 'date',
  },
  {
    label: '研究结束时间：',
    prop: 'researchStartAfter',
    type: 'date',
  },
  {
    label: '承担单位：',
    prop: 'leadingUnitId',
    type: 'select',
    options: [],
  },
  {
    label: '项目级别：',
    prop: 'projectLevel',
    type: 'select',
    options: dictStore.getDictType('project_level'),
  },
  {
    label: '项目类型：',
    prop: 'projectType',
    type: 'tree',
    options: dictStore.getDictType('project_type'),
  },
  {
    label: '是否重点项目：',
    prop: 'keyProject',
    type: 'select',
    options: [],
  },
])

const topicDescriptions = [
  {
    label: '课题名称',
    value: 'name',
  },
  {
    label: '课题类型',
    value: 'type',
  },
  {
    label: '专业领域',
    value: 'subjectAreaText',
  },
  {
    label: '研究周期',
    value: 'researchDate',
  },
  {
    label: '预计投入经费(万元)',
    value: 'estimatedBudget',
  },
  {
    label: '是否需要外协',
    value: 'externalCooperationRequired',
  },
  {
    label: '承担单位',
    value: 'leadingUnitName',
  },
  {
    label: '课题负责人',
    value: 'leader',
  },
  {
    label: '协作单位',
    value: 'collaboratingUnitNames',
  },
  {
    label: '项目编号',
    value: 'projectCode',
  },
  {
    label: '项目名称',
    value: 'projectName',
  },
  {
    label: '项目等级',
    value: 'projectLevel',
  },
  {
    label: '项目类型',
    value: 'projectType',
  },
  {
    label: '是否重点项目',
    value: 'keyProject',
  },
  {
    label: '项目负责人',
    value: 'headerName',
  },
]

const detailsDescriptions = reactive({
  top: [
    {
      label: '申报记录ID',
      value: 'id',
    },
    {
      label: '记录创建人',
      value: '121',
    },
    {
      label: '记录创建时间',
      value: 'createTime',
    },
  ],
  projectDescriptions: [
    {
      label: '项目编号',
      value: 'projectCode',
    },
    {
      label: '项目名称',
      value: 'projectName',
    },
    {
      label: '项目等级',
      value: 'projectLevel',
    },
    {
      label: '项目类型',
      value: 'projectType',
    },
    {
      label: '是否重点项目',
      value: 'keyProject',
    },
    {
      label: '项目负责人',
      value: 'headerName',
    },
  ],
  subjectDescriptions: [
    {
      label: '课题编号',
      value: 'topicId',
    },
    {
      label: '课题名称',
      value: 'topicName',
    },
    {
      label: '课题类型',
      value: 'topicType',
    },
    {
      label: '专业领域',
      value: 'subjectAreaStr',
    },
    {
      label: '研究周期',
      value: 'researchDate',
    },
    {
      label: '预计投入经费(万元)',
      value: 'estimatedBudget',
    },
    {
      label: '是否需要外协',
      value: 'externalCooperationRequired',
    },
    {
      label: '承担单位',
      value: 'leadingUnitName',
    },
    {
      label: '协作单位',
      value: 'collaboratingUnitNames',
    },
    {
      label: '课题负责人',
      value: 'leader',
    },
  ],
  otherDescriptions: [
    {
      label: '上报单位',
      value: 'reportUnitName',
    },
    {
      label: '上报人',
      value: 'reportPersonName',
    },
  ],
})

const form1 = ref([
  {
    label: '成果登记号:',
    prop: 'achievementId',
    type: 'input',
  },
  {
    label: '推荐单位:',
    prop: 'recommendUnit',
    type: 'select',
    options: [],
  },
  {
    label: '推荐日期:',
    prop: 'recommendDate',
    type: 'date',
  },
  {
    label: '推荐等级:',
    prop: 'recommendLevel',
    type: 'select',
    options: dictStore.getDictType('recommend_level'),
  },
  {
    label: '推荐单位联系人姓名:',
    prop: 'recommendPersonName',
    type: 'select',
    options: [],
  },
  {
    label: '推荐单位联系人电话:',
    prop: 'recommendPersonMobile',
    type: 'input',
  },
  {
    label: '推荐单位联系人E-mail:',
    prop: 'recommendPersonEmail',
    type: 'input',
  },
  {
    label: '初评等级:',
    prop: 'preReviewLevel',
    type: 'select',
    options: dictStore.getDictType('recommend_level'),
  },
])

const form2 = ref([
  {
    label: '概要:',
    prop: 'summary',
    type: 'textarea',
  },
  {
    label: '创新点:',
    prop: 'innovationPoints',
    type: 'textarea',
  },
  {
    label: '应用推广情况:',
    prop: 'promotionInfo',
    type: 'textarea',
  },
  {
    label: '经济效益:',
    prop: 'economicBenefits',
    type: 'textarea',
  },
])

const form2Craft = ref([
  {
    label: '概要、创新点、应用推广情况及经济效益:',
    prop: 'recommendProjectProfile',
    type: 'textarea',
  },
])

const form3 = ref([
  {
    label: '立项背景:',
    prop: 'projectApprovalBackground',
    type: 'textarea',
  },
  {
    label: '技术方案与研究开发内容:',
    prop: 'technologyStudyContent',
    type: 'textarea',
  },
  {
    label: '与当前国内外同类技术或产品的综合比较、存在问题及改进措施:',
    prop: 'compareProblemMeasure',
    type: 'textarea',
  },
  {
    label: '技术创新点:',
    prop: 'technologyInnovationPoints',
    type: 'textarea',
  },
  {
    label: '应用、推广情况:',
    prop: 'technologyPromotionInfo',
    type: 'textarea',
  },
])

const form3Craft = ref([
  {
    label: '1、立项背景:',
    prop: 'projectApprovalBackground',
    type: 'textarea',
  },
  {
    label: '2、新技术推广或集成配套内容:',
    prop: 'b',
    type: 'textarea',
  },
  {
    label: '3、与当前国内外同类技术或产品的综合比较:',
    prop: 'c',
    type: 'textarea',
  },
  {
    label: '4、应用规模与效果:',
    prop: 'd',
    type: 'textarea',
  },
])

const form4 = [
  {
    label: '科技经费投入总额:',
    prop: 'a',
    type: 'input',
  },
  {
    label: '已实现利润总额:',
    prop: 'b',
    type: 'input',
  },
]

const form41 = [
  {
    label: '经济效益计算说明（包括计算依据、公式、计算过程和结果）:',
    prop: 'economicBenefitsDescribe',
    type: 'textarea',
  },
  {
    label: '单位财务部门审核意见:',
    prop: 'auditOpinion',
    type: 'textarea',
  },
]

const sumNum = (list, field) => {
  let count: number = 0
  list.forEach((item) => {
    count += parseFloat(item[field])
  })
  return count
}

const form4GridOptions = ref<VxeGridProps<any>>({
  border: true,
  showFooter: true,
  showOverflow: true,
  height: 300,
  align: 'center',
  loading: false,
  columnConfig: {
    resizable: true,
  },
  editConfig: {
    trigger: 'manual',
    mode: 'row',
    showStatus: true,
  },
  columns: [
    {
      field: 'year',
      title: '栏目年份',
      editRender: {},
      slots: { edit: 'year_edit' },
    },
    {
      field: 'profit',
      title: '新增利润',
      editRender: {},
      slots: { edit: 'profit_edit' },
    },
    {
      field: 'conserve',
      title: '节约成本、费用',
      editRender: {},
      slots: { edit: 'conserve_edit' },
    },
    {
      field: 'total',
      title: '合计',
      editRender: {},
    },
    {
      title: '操作',
      width: 200,
      slots: { default: 'operate' },
      fixed: 'right',
    },
  ],
  data: [],
  footerMethod({ columns, data }) {
    return [
      columns.map((column, index) => {
        if (index === 0) {
          return '累计'
        }
        if (['profit', 'conserve', 'total'].includes(column.field)) {
          return sumNum(data, column.field)
        }
        return ''
      }),
    ]
  },
})

const form4CraftOPtions = ref<VxeGridProps<any>>({
  border: true,
  showFooter: true,
  height: 300,
  align: 'center',
  loading: false,
  columnConfig: {
    resizable: true,
  },
  editConfig: {
    trigger: 'manual',
    mode: 'row',
    showStatus: true,
  },
  columns: [
    {
      field: 'year',
      title: '栏目年份',
      editRender: {},
      slots: { edit: 'year_edit' },
    },
    {
      field: 'profit',
      title: '技术创收',
      editRender: {},
      slots: { edit: 'profit_edit' },
    },
    {
      field: 'conserve',
      title: '技术创效',
      editRender: {},
      slots: { edit: 'conserve_edit' },
    },
    {
      field: 'use',
      title: '应用井数',
      editRender: { name: 'VxeInput' },
      // slots: { edit: 'use_edit' },
    },
    {
      title: '操作',
      width: 200,
      slots: { default: 'operate' },
      fixed: 'right',
    },
  ],
  data: [],
  footerMethod({ columns, data }) {
    return [
      columns.map((column, index) => {
        if (index === 0) {
          return '累计'
        }
        if (['profit', 'conserve', 'use'].includes(column.field)) {
          return sumNum(data, column.field)
        }
        return ''
      }),
    ]
  },
})

const form5GridOptions = reactive<VxeGridProps<any>>({
  border: true,
  showFooter: false,
  height: 300,
  align: 'center',
  loading: false,
  columnConfig: {
    resizable: true,
  },
  editConfig: {
    trigger: 'manual',
    mode: 'row',
    showStatus: true,
  },
  editRules: {
    // name: [{ required: true }],
    // time: [{ required: true }],
    // level: [{ required: true }],
  },
  columns: [
    {
      field: 'time',
      title: '获奖时间',
      editRender: {},
      slots: { edit: 'time_edit' },
    },
    {
      field: 'name',
      title: '奖励名称',
      // editRender: { name: 'VxeInput' },
      editRender: {},
      slots: { edit: 'name_edit' },
    },
    {
      field: 'level',
      title: '奖励等级',
      // editRender: {
      //   name: 'VxeSelect',
      //   props: { options: [{ label: '哈哈哈', value: '1' }] },
      // },
      editRender: {},
      slots: { edit: 'level_edit' },
    },
    {
      field: 'department',
      title: '授奖部门',
      editRender: {},
      slots: { edit: 'department_edit' },
    },
    {
      title: '操作',
      width: 200,
      slots: { default: 'operate' },
      fixed: 'right',
    },
  ],
  data: [],
})

const form6GridOptions = reactive<VxeGridProps<any>>({
  border: true,
  showFooter: false,
  height: 300,
  align: 'center',
  loading: false,
  columnConfig: {
    resizable: true,
  },
  editConfig: {
    trigger: 'manual',
    mode: 'row',
    showStatus: true,
  },
  columns: [
    {
      field: 'countries',
      title: '国别',
      editRender: {},
      slots: { edit: 'countries_edit' },
    },
    {
      field: 'type',
      title: '专利类型',
      editRender: {},
      slots: { edit: 'type_edit' },
    },
    {
      field: 'numbers',
      title: '专利号/申请号',
      editRender: {},
      slots: { edit: 'numbers_edit' },
    },
    {
      field: 'name',
      title: '专利名称',
      editRender: {},
      slots: { edit: 'name_edit' },
    },
    {
      title: '操作',
      width: 200,
      slots: { default: 'operate' },
      fixed: 'right',
    },
  ],
  data: [],
})

const form7GridOptions = reactive<VxeGridProps<any>>({
  border: true,
  showFooter: false,
  height: 300,
  align: 'center',
  loading: false,
  columnConfig: {
    resizable: true,
  },
  editConfig: {
    trigger: 'manual',
    mode: 'row',
    showStatus: true,
  },
  columns: [
    { title: '序号', type: 'seq', width: 50 },
    {
      field: 'no',
      title: '编号',
      editRender: {},
      slots: { edit: 'no_edit' },
    },
    {
      field: 'time',
      title: '认定时间',
      editRender: {},
      slots: { edit: 'time_edit' },
    },
    {
      field: 'name',
      title: '技术秘密名称',
      editRender: {},
      slots: { edit: 'name_edit' },
    },
    {
      title: '操作',
      width: 200,
      slots: { default: 'operate' },
      fixed: 'right',
    },
  ],
  data: [],
})

const form8 = [
  {
    label: '姓名:',
    prop: 'a',
    type: 'select',
    options: [],
  },
  {
    label: '性别:',
    prop: 'b',
    type: 'select',
    options: [],
  },
  {
    label: '出生日期:',
    prop: 'c',
    type: 'date',
  },
  {
    label: '工作单位:',
    prop: 'd',
    type: 'select',
    options: [],
  },
  {
    label: '职务、职称:',
    prop: 'e',
    type: 'input',
  },
  {
    label: '单位电话:',
    prop: 'f',
    type: 'input',
  },
  {
    label: '手机:',
    prop: 'g',
    type: 'input',
  },
  {
    label: '电子信箱:',
    prop: 'h',
    type: 'input',
  },
  {
    label: '通讯地址:',
    prop: 'i',
    type: 'input',
  },
  {
    label: '邮政编码:',
    prop: 'j',
    type: 'input',
  },
  {
    label: '毕业学校:',
    prop: 'k',
    type: 'input',
  },
  {
    label: '毕业时间:',
    prop: 'l',
    type: 'date',
  },
  {
    label: '学历/学位:',
    prop: 'm',
    type: 'select',
    options: [],
  },
]

const form8GridOptions = reactive<VxeGridProps<any>>({
  border: true,
  showFooter: true,
  height: 300,
  align: 'center',
  loading: false,
  columnConfig: {
    resizable: true,
  },
  editConfig: {
    trigger: 'manual',
    mode: 'row',
    showStatus: true,
  },
  columns: [
    // { title: '序号', type: 'seq', width: 50 },
    {
      field: 'date',
      title: '起止时间',
      editRender: {},
      slots: { edit: 'date_edit' },
    },
    {
      field: 'content',
      title: '主要贡献',
      editRender: {},
      slots: { edit: 'content_edit' },
    },
    {
      field: 'dayNum',
      title: '工作天数',
      editRender: {},
      slots: { edit: 'dayNum_edit' },
    },
    {
      title: '操作',
      width: 200,
      slots: { default: 'operate' },
      fixed: 'right',
    },
  ],
  data: [],
  footerMethod({ columns, data }) {
    return [
      columns.map((column, index) => {
        if (index === 1) {
          return '工作时间合计（天）'
        }
        if (['dayNum'].includes(column.field)) {
          return sumNum(data, column.field)
        }
        return ''
      }),
    ]
  },
})

const form9 = [
  {
    label: '单位名称:',
    prop: 'a',
    type: 'select',
    options: [],
  },
  {
    label: '联系人:',
    prop: 'b',
    type: 'select',
    options: [],
  },
  {
    label: '单位电话:',
    prop: 'c',
    type: 'input',
  },
  {
    label: '住宅电话:',
    prop: 'd',
    type: 'input',
    options: [],
  },
  {
    label: '手机:',
    prop: 'e',
    type: 'input',
  },
  {
    label: '电子信箱:',
    prop: 'f',
    type: 'input',
  },
  {
    label: '传真:',
    prop: 'g',
    type: 'input',
  },
  {
    label: '电子信箱:',
    prop: 'h',
    type: 'input',
  },
  {
    label: '通讯地址:',
    prop: 'i',
    type: 'input',
  },
  {
    label: '邮政编码:',
    prop: 'j',
    type: 'input',
  },
]

export {
  gridOptions,
  formList,
  valueoptions,
  topicDescriptions,
  form1,
  form2,
  form2Craft,
  form3,
  form3Craft,
  form4,
  form4GridOptions,
  form4CraftOPtions,
  form41,
  form5GridOptions,
  form6GridOptions,
  form7GridOptions,
  form8,
  form8GridOptions,
  form9,
  detailsDescriptions,
}
